fix(storage): support updated GapicCallable metadata in tests - #18031
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the unit test test_init_default_client_info in test_read_client_v1.py to safely retrieve metadata from wrapped methods by checking _default_metadata before falling back to _metadata. This ensures the test is more resilient to changes in how metadata is stored on wrapped methods. There are no review comments, and I have no additional feedback to provide.
| ( | ||
| header_value | ||
| for header, header_value in wrapped_method._metadata | ||
| for header, header_value in metadata |
Contributor
There was a problem hiding this comment.
Can you try to write this test in a way that doesn't depend on internal attributes? That would make it more resilient to these kinds of failures in the future
One option is to mock wrap_method:
@pytest.mark.parametrize(
"module_under_test",
["google.cloud.bigquery_storage_v1", "google.cloud.bigquery_storage_v1beta2"],
)
def test_init_default_client_info(module_under_test):
mut = importlib.import_module(module_under_test)
creds = mock.Mock(spec=credentials.Credentials)
expected_client_info = f"gccl/{mut.__version__}"
with mock.patch("google.api_core.gapic_v1.method.wrap_method") as mock_wrap:
mut.BigQueryWriteClient(credentials=creds)
assert mock_wrap.call_count > 0 # <- maybe set the expected number here? Or something more robust?
for call in mock_wrap.call_args_list:
client_info = call.kwargs.get("client_info")
assert client_info is not None
assert expected_client_info in client_info.to_user_agent()
Contributor
Author
There was a problem hiding this comment.
Thanks @daniel-sanche for the suggestion! Done.
shuoweil
force-pushed
the
shuowei-fix-client-info-metadata-test
branch
from
August 7, 2026 23:43
4b57ac5 to
af634b0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In google-api-core>=2.34.0 (PR #17616), _GapicCallable replaced the internal _metadata attribute with _default_metadata / _x_goog_api_client.
This PR updates test_init_default_client_info in packages/google-cloud-bigquery-storage/tests/unit/test_read_client_v1.py to check _default_metadata with a fallback to _metadata, maintaining compatibility across both older and newer google-api-core releases.
Fixes #<543999765> 🦕